<?php

use EWeiLink\JuPai\Message;
use EWeiLink\JuPai\Planner;
use \EWeiLink\JuPai\Contact;
use Illuminate\Database\Eloquent\Collection;
use EWeiLink\JuPai\JpCustomer;

/**
 * Created by PhpStorm.
 * User: jochen
 * Date: 2017/1/13
 * Time: 下午6:11
 */
class TestModel extends ModelTestCase
{
    public function testMessage()
    {
        $message = Message::create([
            'content' => '123123',
            'type' => 'text_msg',
            'from' => 'xxxx',
            'createTime' => time(),
        ]);
        $_id = $message->id;
        unset($message);
        $message = Message::find($_id);
        $this->preDestroy($message);
        $this->assertNotNull($message);
    }

    public function testCustomer()
    {
        $someone = \EWeiLink\JuPai\Customer::first();
        $this->assertNotNull($someone);
    }

    public function testEntity()
    {
        $options = new \EWeiLink\JuPai\OptionsEntity();
        dumps(json_encode($options));
    }

    public function testList()
    {
//        $jpCustomer = JpCustomer::where('customerId',123.0)->get()->toArray();
//        dd($jpCustomer);
        $options = new \EWeiLink\JuPai\Services\ContactRepo();
        $data = $options->getContactList();

        if (!empty($data)) {
//            $page = request()->input('page', 1);
//            $perPage = request()->input('perPage', 20);
            $res_data = [
                'total' => $data->count(),
                'per_page' => 20,
                'page' => 1,
                'data' => array_values($data->forPage(1, 20)
                    ->toArray()),
            ];
        }
        dumps(json_encode($res_data));
        die;
    }

    public function testBind(){
        $options = new \EWeiLink\JuPai\Services\ContactRepo();
        $data = $options->bind(1,1,1);

    }
    public function testInt()
    {
        $options = new \EWeiLink\JuPai\Http\Controllers\SupportController();
        $data = $options->initOptions();
        dumps(json_encode($data));
    }
}